require "active_record"

##
# This class is used for getting the comments from the wordpress database
# 
# == Examples:
#   User.find(1).comments
# <em>The above will find the user with id of 1 and retrieve all of the comments they have ever made</em>
#   Post.find(1).comments
# <em>The above will find the post with id of 1 and retrieve all of the comments from that post</em>
#   Comment.find(1)
# <em>The above will find the comment with id of 1</em>
# 
# == Inherited methods
# [find <em>id</em>]  Retrieves the comment with the sepcified id
# [all]  Retrieves all of the comments in the database
# 
# == Database Keys
# [comment_ID <em>alias: id</em>] The comments id
# [comment_post_ID <em>alias: post.id</em>]
# 	The post id where the comment was posted
# 	  Comment.find(1).post
# 	<em>The above returns the Post that the comment belongs to</em>
# [comment_author] The name of the auther (could be stored in user.name, User#name)
# [comment_author_email] The email of the author (could be stored in user.email, User#email)
# [comment_author_url] The url of the author (could be stored in user.url, User#url)
# [comment_author_IP] The ip of the author
# [comment_date] The date the comment was posted
# [comment_date_gmt] The date the comment was posted in gmt/utc time
# [comment_content <em>alias: Comment#content</em>] The content of the comment
# [comment_karma] The comment karma
# [comment_approved] If the comment has been approved or not
# [comment_agent] The agent of the comment
# [comment_type] The type of comment
# [comment_parent] The parent comment id if any
# [user_id]
# 	The user id of the author (0 if not registered user)
# 	  Comment.find(1).user
# 	<em>The above returns the User that posted the comment if user_id isn't 0</em>


class Comment < ActiveRecord::Base
	set_table_name :wp_comments
	set_primary_key :comment_ID
	
	belongs_to :page_post
	belongs_to :user
	
	validates_presence_of :comment_post_ID
	
	before_save :set_default_values
	
	alias_attribute :content, :comment_content
	
	private
	def set_default_values
		t = Time.now
		self.comment_date = t
		self.comment_date_gmt = t.gmtime
	end
end